{% extends 'bugs/base.html' %}

{% block content %}


<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="{% url 'bugs:index' %}">Software Afair Management System</a>
        </div>
    </div>
</nav>

<div class="container">
    <form action="/update_bug/" method="post" accept-charset="utf-8" class="form" role="form" enctype="multipart/form-data">
        {% csrf_token %}
        {% for data in bug %}
        <input type="hidden" name="id" value={{ data.id }}>
        <input type="hidden" name="csrfmiddlewaretoken" value="tcKPX6l1AsO1DFMDs7LUZqCBkKRT7mZP">
        <legend>Update Bug</legend>
        <input type="hidden" name="csrfmiddlewaretoken" value="tcKPX6l1AsO1DFMDs7LUZqCBkKRT7mZP">
        {% for project in project_data %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_project">专案</label>
            <div class="col-sm-10">
                {% if project.type %}
                <input readonly="readonly" class="form-control" id="project" name="project" readonly
                       value="{{ project.name }}--{{ project.type }}">
                {% else %}
                <input readonly="readonly" class="form-control" id="project" name="project" readonly
                       value={{ project.name }}>
                {% endif %}
            </div>
        </div>
        {% endfor %}
        <br>
        <br>
        <!--版本-->
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_version">版本</label>
            <div class="col-sm-10">
                <input class="form-control" id="id_version" maxlength="40" name="version" type="text"
                       readonly value={{ data.version }}>
            </div>
        </div>
        <br>
        <br>
        <!--状态-->
        {% if authority == '2' %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_version">状态</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_state" name="state">
                    <a value="{{ data.state }}">{{ data.state }}</a>
                    <option value="已完成">已完成</option>
                    <option value="验证有误">验证有误</option>
                </select>
            </div>
        </div>
        {% elif authority == '1' %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_state">状态</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_state" name="state">
                    <p data-value="{{ data.state }}">{{ data.state }}</p>
                    <option value="待验证">待验证</option>
                    <option value="处理中">处理中</option>
                    <option value="已完成">已完成</option>
                </select>
            </div>
        </div>
        <br>
        {% else %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_state">状态</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_state" name="state">
                    <option value="带指派">待指派</option>
                    <option value="处理中">处理中</option>
                    <option value="已完成">已完成</option>
                    <option value="待验证">待验证</option>
                    <option value="验证有误">验证有误</option>
                </select>
            </div>
        </div>
        {% endif %}
        <!--优先权-->
        {% if authority == '0' %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_level">优先权</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_level" name="level">
                    <a value="{{ data.level }}">{{ data.level }}</a>
                    <option value="低">低</option>
                    <option value="一般">一般</option>
                    <option value="紧急">紧急</option>
                </select>
            </div>
        </div>
        {% else %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_level">优先权</label>
            <div class="col-sm-10">
                <input class="form-control" id="level" name="level" readonly
                       value={{ data.level }}>
            </div>
        </div>
        <br>
        <br>
        {% endif %}
        <!--出现频率-->
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_emerge_times">出现频率</label>
            <div class="col-sm-10">
                <input class="form-control" id="emerge_times" name="emerge_times" readonly
                       value={{ data.emerge_times }}>
            </div>
        </div>
        <br>
        <br>
        <!--影响程度-->
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_severity">影响程度</label>
            <div class="col-sm-10">
                <input class="form-control" id="severity" name="severity" readonly
                       value={{ data.severity }}>
            </div>
        </div>
        <br>
        <!--难度-->
        {% if authority == '0' or authority == '1' %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_difficult">难度</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_difficult" name="difficult">
                    <option value="低">低</option>
                    <option value="一般">一般</option>
                    <option value="难">难</option>
                </select>
            </div>
        </div>
        {% endif %}
        <br>
        <!--描述-->
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_description">描述</label>
            <div class="col-sm-10">
                <input class="form-control" id="description" name="description" readonly
                       value={{ data.description }}>
            </div>
        </div>
        <!--预计完成日期-->
        {% if authority == '0' or authority == '1' %}
        {% if data.estime == DateTime.MinValue %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_estime">预计完成日期</label>
            <div class="col-sm-10">
                <input class="" id="id_estime" name="estime" type="datetime-local"
                       value=" "/>
            </div>
        </div>
        <br>
        {% else %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_estime">预计完成日期</label>
            <div class="col-sm-10">
                <input class="" id="id_estime" name="estime" type=""
                       value="{{ data.estime | date:" Y-m-d H:i:s"}} "/>
            </div>
        </div>
        {% endif %}
        {% endif %}
        <!--图片-->
        {% if images %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_description">图片</label>
            <div class="col-sm-10">
                {% for image in images %}
                <img class="thumb_img" data-toggle="modal" data-target="#myModal"
                     style="float: left;width: 150px;padding-left: 5px;cursor: pointer;"
                     src={{ image.image.url }}>
                {% endfor %}
            </div>
        </div>
        <br>
        <br>
        {% endif %}
        <!-- 可以继续新增图片 -->
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_image">新增图片</label>
            <div class="col-sm-10">
                <input class="form-control" id="id_image" name="image" type="file" multiple="multiple">

            </div>
        </div>
        <!--bug发起人信息-->
        {% for owner in owner_message %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_owner">发起人信息</label>
            <div class="col-sm-10">
                <input class="" id="owner_c_name" name="owner_c_name" readonly
                       value={{ owner.c_name }}>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input class="" id="owner_c_phone" name="owner_c_phone" readonly
                       value={{ owner.phone }}>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input class="" id="owner_c_email" name="owner_c_email" readonly
                       value={{ owner.email }}>
            </div>
        </div>
        {% endfor %}
        <br>
        <!--修改受理人-->
        {% if authority == '0' %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_assignee">受理人</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_assignee" name="assignee">
                    {% for engineer in engineer_data %}
                    <option value="{{ engineer.user_id }}">{{ engineer.c_name }}</option>
                    {% endfor %}
                </select>

            </div>
        </div>
        {% elif authority == '1' %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_assignee">受理人</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_assignee" name="assignee">
                    {% for engineer in engineer_data %}
                    <option value="{{ engineer.user_id }}">{{ engineer.c_name }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>
        {% endif %}
        <!--受理人信息-->
        {% for assignee in assignee_message %}
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_assignee_message">受理人信息</label>
            <div class="col-sm-10">
                <input class="" id="assignee_message_name" name="assignee_message_name" readonly
                       value={{ assignee.c_name }}>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input class="" id="assignee_message_phone" name="assignee_message_phone" readonly
                       value={{ assignee.phone }}>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input class="" id="assignee_message_email" name="assignee_message_email" readonly
                       value={{ assignee.email }}>
            </div>
        </div>
        {% endfor %}
        <!--路径-->
        {% for project in project_data %}
        <br>
        <div class="form-group">
            <label class="col-sm-2 control-label" for="id_path">路径/网址</label>
            <div class="col-sm-10">
                <input class="form-control" id="path" name="path" readonly
                       value={{ project.path }}>
                &nbsp;&nbsp;&nbsp;&nbsp;
            </div>
        </div>
        {% endfor %}
        <br>
        <br>
        {% if message %}
        <p value="{{ message }}">{{ message }}</p>
        {% endif %}
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <br>
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
        {% endfor %}

    </form>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
            </div>
            <div class="modal-body">
                <img style="width: 100%;" id="big_pic" src="">
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(".thumb_img").click(function () {
        // console.log($(this)[0].src)
        $("#big_pic").attr('src', $(this)[0].src);
    })
</script>
{% endblock %}
